package pkg

import (
	"day12_16_shop/internal/api/request"
	"math/rand"
)

var price float64

func HowMuch(shop *request.ShopCreateRequest) float64 {
	if shop.Phone == "苹果" || shop.Phone == "三星" {
		PhoneForTall(shop)
	} else {
		PhoneForSmall(shop)
	}
	return price
}

func PhoneForTall(shop *request.ShopCreateRequest) {
	if shop.HowBig >= 512 {
		if shop.WhereBuy == "国行" {
			if shop.GoodOrBad == 1 {
				price = float64(rand.Intn(1000) + 5000)
			}
			if shop.GoodOrBad == 2 {
				price = float64(rand.Intn(1000) + 3000)
			}
			if shop.GoodOrBad == 3 {
				price = float64(rand.Intn(1000) + 2000)
			}
		} else {
			if shop.GoodOrBad == 1 {
				price = float64(rand.Intn(1000) + 3000)
			}
			if shop.GoodOrBad == 2 {
				price = float64(rand.Intn(1000) + 2000)
			}
			if shop.GoodOrBad == 3 {
				price = float64(rand.Intn(1000) + 1000)
			}
		}
	} else if shop.HowBig >= 128 && shop.HowBig < 512 {
		if shop.WhereBuy == "国行" {
			if shop.GoodOrBad == 1 {
				price = float64(rand.Intn(1000) + 2000)
			}
			if shop.GoodOrBad == 2 {
				price = float64(rand.Intn(1000) + 1000)
			}
			if shop.GoodOrBad == 3 {
				price = float64(rand.Intn(1000) + 500)
			}
		} else {
			if shop.GoodOrBad == 1 {
				price = float64(rand.Intn(1000) + 1000)
			}
			if shop.GoodOrBad == 2 {
				price = float64(rand.Intn(1000) + 700)
			}
			if shop.GoodOrBad == 3 {
				price = float64(rand.Intn(1000) + 500)
			}
		}
	} else {
		if shop.WhereBuy == "国行" {
			price = float64(rand.Intn(800) + 500)
		} else {
			price = float64(rand.Intn(500) + 500)
		}
	}
}

func PhoneForSmall(shop *request.ShopCreateRequest) {
	if shop.HowBig >= 512 {
		if shop.GoodOrBad == 1 {
			price = float64(rand.Intn(900) + 5000)
		}
		if shop.GoodOrBad == 2 {
			price = float64(rand.Intn(900) + 3000)
		}
		if shop.GoodOrBad == 3 {
			price = float64(rand.Intn(900) + 2000)
		}
	} else if shop.HowBig >= 128 && shop.HowBig < 512 {
		if shop.GoodOrBad == 1 {
			price = float64(rand.Intn(900) + 5000)
		}
		if shop.GoodOrBad == 2 {
			price = float64(rand.Intn(900) + 3000)
		}
		if shop.GoodOrBad == 3 {
			price = float64(rand.Intn(900) + 2000)
		}
	} else {
		price = float64(rand.Intn(800) + 500)
	}
}
